package com.github.zyf.ioaj.utils.basedata;

/**
 * @author zyf
 */
public class ArrayUtils {

    private ArrayUtils() {
    }

    /* 类型转换 */

    public static Double[] toObject(double[] array) {
        int i;
        int len = array.length;
        Double[] newArray = new Double[len];
        for (i = 0; i < len; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    public static Integer[] toObject(int[] array) {
        int i;
        int len = array.length;
        Integer[] newArray = new Integer[len];
        for (i = 0; i < len; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    public static Float[] toObject(float[] array) {
        int i;
        int len = array.length;
        Float[] newArray = new Float[len];
        for (i = 0; i < len; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    public static Long[] toObject(long[] array) {
        int i;
        int len = array.length;
        Long[] newArray = new Long[len];
        for (i = 0; i < len; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    public static double[] toPrimitive(Double[] array) {
        int i;
        int len = array.length;
        double[] newArray = new double[len];
        for (i = 0; i < len; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    public static int[] toPrimitive(Integer[] array) {
        int i;
        int len = array.length;
        int[] newArray = new int[len];
        for (i = 0; i < len; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    public static float[] toPrimitive(Float[] array) {
        int i;
        int len = array.length;
        float[] newArray = new float[len];
        for (i = 0; i < len; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    public static long[] toPrimitive(Long[] array) {
        int i;
        int len = array.length;
        long[] newArray = new long[len];
        for (i = 0; i < len; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    /* 两数组相加 */

    public static double[] plus(double[] array1, double[] array2) {
        int len = array1.length;
        double[] newArray = new double[len];
        int i;
        for (i = 0; i < len; i++) {
            newArray[i] = array1[i] + array2[i];
        }
        return newArray;
    }

    public static int[] plus(int[] array1, int[] array2) {
        int len = array1.length;
        int[] newArray = new int[len];
        int i;
        for (i = 0; i < len; i++) {
            newArray[i] = array1[i] + array2[i];
        }
        return newArray;
    }

    public static float[] plus(float[] array1, float[] array2) {
        int len = array1.length;
        float[] newArray = new float[len];
        int i;
        for (i = 0; i < len; i++) {
            newArray[i] = array1[i] + array2[i];
        }
        return newArray;
    }

    public static long[] plus(long[] array1, long[] array2) {
        int len = array1.length;
        long[] newArray = new long[len];
        int i;
        for (i = 0; i < len; i++) {
            newArray[i] = array1[i] + array2[i];
        }
        return newArray;
    }

    public static Double[] plus(Double[] array1, Double[] array2) {
        int len = array1.length;
        Double[] newArray = new Double[len];
        int i;
        for (i = 0; i < len; i++) {
            newArray[i] = array1[i] + array2[i];
        }
        return newArray;
    }

    public static Integer[] plus(Integer[] array1, Integer[] array2) {
        int len = array1.length;
        Integer[] newArray = new Integer[len];
        int i;
        for (i = 0; i < len; i++) {
            newArray[i] = array1[i] + array2[i];
        }
        return newArray;
    }

    public static Float[] plus(Float[] array1, Float[] array2) {
        int len = array1.length;
        Float[] newArray = new Float[len];
        int i;
        for (i = 0; i < len; i++) {
            newArray[i] = array1[i] + array2[i];
        }
        return newArray;
    }

    public static Long[] plus(Long[] array1, Long[] array2) {
        int len = array1.length;
        Long[] newArray = new Long[len];
        int i;
        for (i = 0; i < len; i++) {
            newArray[i] = array1[i] + array2[i];
        }
        return newArray;
    }

    /* 求和部分 */

    public static double sum(double[] array) {
        double sum = 0.0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static float sum(float[] array) {
        float sum = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static int sum(int[] array) {
        int sum = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static long sum(long[] array) {
        long sum = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static Double sum(Double[] array) {
        Double sum = 0.0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static Float sum(Float[] array) {
        Float sum = 0f;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static Integer sum(Integer[] array) {
        Integer sum = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static Long sum(Long[] array) {
        Long sum = 0L;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    /* 平均值部分 */

    public static double mean(double[] array) {
        double sum = 0.0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum / len;
    }

    public static float mean(float[] array) {
        float sum = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum / len;
    }

    public static double mean(int[] array) {
        int sum = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return (double) sum / len;
    }

    public static long mean(long[] array) {
        long sum = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum / len;
    }

    public static Double mean(Double[] array) {
        Double sum = 0.0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum / len;
    }

    public static Float mean(Float[] array) {
        Float sum = 0f;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum / len;
    }

    public static Double mean(Integer[] array) {
        Integer sum = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return (double) (sum / len);
    }

    public static Long mean(Long[] array) {
        Long sum = 0L;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum / len;
    }

    /* 最大值部分 */

    public static double max(double[] array) {
        double max = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            max = Math.max(max, array[i]);
        }
        return max;
    }

    public static float max(float[] array) {
        float max = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            max = Math.max(max, array[i]);
        }
        return max;
    }

    public static int max(int[] array) {
        int max = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            max = Math.max(max, array[i]);
        }
        return max;
    }

    public static long max(long[] array) {
        long max = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            max = Math.max(max, array[i]);
        }
        return max;
    }

    public static Double max(Double[] array) {
        Double max = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            max = Math.max(max, array[i]);
        }
        return max;
    }

    public static Float max(Float[] array) {
        Float max = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            max = Math.max(max, array[i]);
        }
        return max;
    }

    public static Integer max(Integer[] array) {
        Integer max = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            max = Math.max(max, array[i]);
        }
        return max;
    }

    public static Long max(Long[] array) {
        Long max = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            max = Math.max(max, array[i]);
        }
        return max;
    }

    public static int maxWithIndex(double[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] > array[index]) index = i;
        }
        return index;
    }

    public static int maxWithIndex(int[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] > array[index]) index = i;
        }
        return index;
    }

    public static int maxWithIndex(float[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] > array[index]) index = i;
        }
        return index;
    }

    public static int maxWithIndex(long[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] > array[index]) index = i;
        }
        return index;
    }

    public static int maxWithIndex(Double[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] > array[index]) index = i;
        }
        return index;
    }

    public static int maxWithIndex(Integer[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] > array[index]) index = i;
        }
        return index;
    }

    public static int maxWithIndex(Float[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] > array[index]) index = i;
        }
        return index;
    }

    public static int maxWithIndex(Long[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] > array[index]) index = i;
        }
        return index;
    }

    /* 最小值部分 */

    public static double min(double[] array) {
        double min = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static float min(float[] array) {
        float min = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static int min(int[] array) {
        int min = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static long min(long[] array) {
        long min = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static Double min(Double[] array) {
        Double min = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static Float min(Float[] array) {
        Float min = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static Integer min(Integer[] array) {
        Integer min = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static Long min(Long[] array) {
        Long min = array[0];
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static int minWithIndex(double[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] < array[index]) index = i;
        }
        return index;
    }

    public static int minWithIndex(int[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] < array[index]) index = i;
        }
        return index;
    }

    public static int minWithIndex(float[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] < array[index]) index = i;
        }
        return index;
    }

    public static int minWithIndex(long[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] < array[index]) index = i;
        }
        return index;
    }

    public static int minWithIndex(Double[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] < array[index]) index = i;
        }
        return index;
    }

    public static int minWithIndex(Integer[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] < array[index]) index = i;
        }
        return index;
    }

    public static int minWithIndex(Float[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] < array[index]) index = i;
        }
        return index;
    }

    public static int minWithIndex(Long[] array) {
        int index = 0;
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            if (array[i] < array[index]) index = i;
        }
        return index;
    }

    /* 数乘部分 */

    public static void numDiv(double[] array, double div) {
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            array[i] = array[i] / div;
        }
    }

    public static void numDiv(int[] array, int div) {
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            array[i] = array[i] / div;
        }
    }

    public static void numDiv(float[] array, float div) {
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            array[i] = array[i] / div;
        }
    }

    public static void numDiv(long[] array, long div) {
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            array[i] = array[i] / div;
        }
    }

    public static void numDiv(Double[] array, Double div) {
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            array[i] = array[i] / div;
        }
    }

    public static void numDiv(Integer[] array, Integer div) {
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            array[i] = array[i] / div;
        }
    }

    public static void numDiv(Float[] array, Float div) {
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            array[i] = array[i] / div;
        }
    }

    public static void numDiv(Long[] array, Long div) {
        int i;
        int len = array.length;
        for (i = 0; i < len; i++) {
            array[i] = array[i] / div;
        }
    }

    /* 查找部分 */

    public static int findIndex(int[] array, int value) {
        for (int i = 0; i < array.length; i++) {
            if (array[i] == value) return i;
        }
        return -1;
    }

    public static int findIndex(double[] array, double value) {
        for (int i = 0; i < array.length; i++) {
            if (array[i] == value) return i;
        }
        return -1;
    }

    public static int findIndex(float[] array, float value) {
        for (int i = 0; i < array.length; i++) {
            if (array[i] == value) return i;
        }
        return -1;
    }

    public static int findIndex(long[] array, long value) {
        for (int i = 0; i < array.length; i++) {
            if (array[i] == value) return i;
        }
        return -1;
    }

    public static int findIndex(Integer[] array, Integer value) {
        for (int i = 0; i < array.length; i++) {
            if (array[i].equals(value)) return i;
        }
        return -1;
    }

    public static int findIndex(Double[] array, Double value) {
        for (int i = 0; i < array.length; i++) {
            if (array[i].equals(value)) return i;
        }
        return -1;
    }

    public static int findIndex(Float[] array, Float value) {
        for (int i = 0; i < array.length; i++) {
            if (array[i].equals(value)) return i;
        }
        return -1;
    }

    public static int findIndex(Long[] array, Long value) {
        for (int i = 0; i < array.length; i++) {
            if (array[i].equals(value)) return i;
        }
        return -1;
    }

    /* 包含 */

    public static boolean hasElement(int[] array, int value) {
        for (int a : array) {
            if (a == value) return true;
        }
        return false;
    }

    public static boolean hasElement(double[] array, double value) {
        for (double a : array) {
            if (a == value) return true;
        }
        return false;
    }

    public static boolean hasElement(float[] array, float value) {
        for (float a : array) {
            if (a == value) return true;
        }
        return false;
    }

    public static boolean hasElement(long[] array, long value) {
        for (long a : array) {
            if (a == value) return true;
        }
        return false;
    }

    public static boolean hasElement(Integer[] array, Integer value) {
        for (Integer a : array) {
            if (a.equals(value)) return true;
        }
        return false;
    }

    public static boolean hasElement(Double[] array, Double value) {
        for (Double a : array) {
            if (a.equals(value)) return true;
        }
        return false;
    }

    public static boolean hasElement(Float[] array, Float value) {
        for (Float a : array) {
            if (a.equals(value)) return true;
        }
        return false;
    }

    public static boolean hasElement(Long[] array, Long value) {
        for (Long a : array) {
            if (a.equals(value)) return true;
        }
        return false;
    }

    /* 排序 */

    /**
     * 归并排序（对原数组进行操作，不产生新数组）
     *
     * @param s     目标数组
     * @param start 起始位置
     * @param end   结束位置
     */
    public static void mergeSort(double[] s, int start, int end) {
        if (start < end) {
            // 两路归并
            int middle = (start + end) / 2;
            mergeSort(s, start, middle);
            mergeSort(s, middle + 1, end);
            // 将两组数据归并
            merge(s, start, middle, middle + 1, end);
        }
    }

    /**
     * 归并排序（对原数组进行操作，不产生新数组）
     *
     * @param s     目标数组
     * @param start 起始位置
     * @param end   结束位置
     */
    public static void mergeSort(int[] s, int start, int end) {
        if (start < end) {
            // 两路归并
            int middle = (start + end) / 2;
            mergeSort(s, start, middle);
            mergeSort(s, middle + 1, end);
            // 将两组数据归并
            merge(s, start, middle, middle + 1, end);
        }
    }

    /**
     * 归并排序（对原数组进行操作，不产生新数组）
     *
     * @param s     目标数组
     * @param start 起始位置
     * @param end   结束位置
     */
    public static void mergeSort(long[] s, int start, int end) {
        if (start < end) {
            // 两路归并
            int middle = (start + end) / 2;
            mergeSort(s, start, middle);
            mergeSort(s, middle + 1, end);
            // 将两组数据归并
            merge(s, start, middle, middle + 1, end);
        }
    }

    /**
     * 归并排序（对原数组进行操作，不产生新数组）
     *
     * @param s     目标数组
     * @param start 起始位置
     * @param end   结束位置
     */
    public static void mergeSort(float[] s, int start, int end) {
        if (start < end) {
            // 两路归并
            int middle = (start + end) / 2;
            mergeSort(s, start, middle);
            mergeSort(s, middle + 1, end);
            // 将两组数据归并
            merge(s, start, middle, middle + 1, end);
        }
    }

    /**
     * 归并排序（对原数组进行操作，不产生新数组）
     *
     * @param s     目标数组
     * @param start 起始位置
     * @param end   结束位置
     */
    public static void mergeSort(Double[] s, int start, int end) {
        if (start < end) {
            // 两路归并
            int middle = (start + end) / 2;
            mergeSort(s, start, middle);
            mergeSort(s, middle + 1, end);
            // 将两组数据归并
            merge(s, start, middle, middle + 1, end);
        }
    }

    /**
     * 归并排序（对原数组进行操作，不产生新数组）
     *
     * @param s     目标数组
     * @param start 起始位置
     * @param end   结束位置
     */
    public static void mergeSort(Integer[] s, int start, int end) {
        if (start < end) {
            // 两路归并
            int middle = (start + end) / 2;
            mergeSort(s, start, middle);
            mergeSort(s, middle + 1, end);
            // 将两组数据归并
            merge(s, start, middle, middle + 1, end);
        }
    }

    /**
     * 归并排序（对原数组进行操作，不产生新数组）
     *
     * @param s     目标数组
     * @param start 起始位置
     * @param end   结束位置
     */
    public static void mergeSort(Long[] s, int start, int end) {
        if (start < end) {
            // 两路归并
            int middle = (start + end) / 2;
            mergeSort(s, start, middle);
            mergeSort(s, middle + 1, end);
            // 将两组数据归并
            merge(s, start, middle, middle + 1, end);
        }
    }

    /**
     * 归并排序（对原数组进行操作，不产生新数组）
     *
     * @param s     目标数组
     * @param start 起始位置
     * @param end   结束位置
     */
    public static void mergeSort(Float[] s, int start, int end) {
        if (start < end) {
            // 两路归并
            int middle = (start + end) / 2;
            mergeSort(s, start, middle);
            mergeSort(s, middle + 1, end);
            // 将两组数据归并
            merge(s, start, middle, middle + 1, end);
        }
    }

    private static void merge(double[] s, int start1, int end1, int start2, int end2) {
        // 数组1、2的两个游标
        int i, j;
        i = start1;
        j = start2;
        // 建立一个数组为两个之和大小，归并到这个数组
        double[] temp = new double[end2 - start1 + 1];
        int k = 0;
        while (i <= end1 && j <= end2) {
            if (s[i] > s[j]) {
                temp[k] = s[j];
                k++;
                j++;
            } else {
                temp[k] = s[i];
                k++;
                i++;
            }
        }
        // 将剩余的元素加入temp中
        while (i <= end1) {
            temp[k] = s[i];
            k++;
            i++;
        }
        while (j <= end2) {
            temp[k] = s[j];
            k++;
            j++;
        }
        // 将temp中数据转移到原数组中
        for (double element : temp) {
            s[start1] = element;
            start1++;
        }
    }

    private static void merge(int[] s, int start1, int end1, int start2, int end2) {
        // 数组1、2的两个游标
        int i, j;
        i = start1;
        j = start2;
        // 建立一个数组为两个之和大小，归并到这个数组
        int[] temp = new int[end2 - start1 + 1];
        int k = 0;
        while (i <= end1 && j <= end2) {
            if (s[i] > s[j]) {
                temp[k] = s[j];
                k++;
                j++;
            } else {
                temp[k] = s[i];
                k++;
                i++;
            }
        }
        // 将剩余的元素加入temp中
        while (i <= end1) {
            temp[k] = s[i];
            k++;
            i++;
        }
        while (j <= end2) {
            temp[k] = s[j];
            k++;
            j++;
        }
        // 将temp中数据转移到原数组中
        for (int element : temp) {
            s[start1] = element;
            start1++;
        }
    }

    private static void merge(float[] s, int start1, int end1, int start2, int end2) {
        // 数组1、2的两个游标
        int i, j;
        i = start1;
        j = start2;
        // 建立一个数组为两个之和大小，归并到这个数组
        float[] temp = new float[end2 - start1 + 1];
        int k = 0;
        while (i <= end1 && j <= end2) {
            if (s[i] > s[j]) {
                temp[k] = s[j];
                k++;
                j++;
            } else {
                temp[k] = s[i];
                k++;
                i++;
            }
        }
        // 将剩余的元素加入temp中
        while (i <= end1) {
            temp[k] = s[i];
            k++;
            i++;
        }
        while (j <= end2) {
            temp[k] = s[j];
            k++;
            j++;
        }
        // 将temp中数据转移到原数组中
        for (float element : temp) {
            s[start1] = element;
            start1++;
        }
    }

    private static void merge(long[] s, int start1, int end1, int start2, int end2) {
        // 数组1、2的两个游标
        int i, j;
        i = start1;
        j = start2;
        // 建立一个数组为两个之和大小，归并到这个数组
        long[] temp = new long[end2 - start1 + 1];
        int k = 0;
        while (i <= end1 && j <= end2) {
            if (s[i] > s[j]) {
                temp[k] = s[j];
                k++;
                j++;
            } else {
                temp[k] = s[i];
                k++;
                i++;
            }
        }
        // 将剩余的元素加入temp中
        while (i <= end1) {
            temp[k] = s[i];
            k++;
            i++;
        }
        while (j <= end2) {
            temp[k] = s[j];
            k++;
            j++;
        }
        // 将temp中数据转移到原数组中
        for (long element : temp) {
            s[start1] = element;
            start1++;
        }
    }

    private static void merge(Double[] s, int start1, int end1, int start2, int end2) {
        // 数组1、2的两个游标
        int i, j;
        i = start1;
        j = start2;
        // 建立一个数组为两个之和大小，归并到这个数组
        Double[] temp = new Double[end2 - start1 + 1];
        int k = 0;
        while (i <= end1 && j <= end2) {
            if (s[i] > s[j]) {
                temp[k] = s[j];
                k++;
                j++;
            } else {
                temp[k] = s[i];
                k++;
                i++;
            }
        }
        // 将剩余的元素加入temp中
        while (i <= end1) {
            temp[k] = s[i];
            k++;
            i++;
        }
        while (j <= end2) {
            temp[k] = s[j];
            k++;
            j++;
        }
        // 将temp中数据转移到原数组中
        for (Double element : temp) {
            s[start1] = element;
            start1++;
        }
    }

    private static void merge(Integer[] s, int start1, int end1, int start2, int end2) {
        // 数组1、2的两个游标
        int i, j;
        i = start1;
        j = start2;
        // 建立一个数组为两个之和大小，归并到这个数组
        Integer[] temp = new Integer[end2 - start1 + 1];
        int k = 0;
        while (i <= end1 && j <= end2) {
            if (s[i] > s[j]) {
                temp[k] = s[j];
                k++;
                j++;
            } else {
                temp[k] = s[i];
                k++;
                i++;
            }
        }
        // 将剩余的元素加入temp中
        while (i <= end1) {
            temp[k] = s[i];
            k++;
            i++;
        }
        while (j <= end2) {
            temp[k] = s[j];
            k++;
            j++;
        }
        // 将temp中数据转移到原数组中
        for (Integer element : temp) {
            s[start1] = element;
            start1++;
        }
    }

    private static void merge(Float[] s, int start1, int end1, int start2, int end2) {
        // 数组1、2的两个游标
        int i, j;
        i = start1;
        j = start2;
        // 建立一个数组为两个之和大小，归并到这个数组
        Float[] temp = new Float[end2 - start1 + 1];
        int k = 0;
        while (i <= end1 && j <= end2) {
            if (s[i] > s[j]) {
                temp[k] = s[j];
                k++;
                j++;
            } else {
                temp[k] = s[i];
                k++;
                i++;
            }
        }
        // 将剩余的元素加入temp中
        while (i <= end1) {
            temp[k] = s[i];
            k++;
            i++;
        }
        while (j <= end2) {
            temp[k] = s[j];
            k++;
            j++;
        }
        // 将temp中数据转移到原数组中
        for (Float element : temp) {
            s[start1] = element;
            start1++;
        }
    }

    private static void merge(Long[] s, int start1, int end1, int start2, int end2) {
        // 数组1、2的两个游标
        int i, j;
        i = start1;
        j = start2;
        // 建立一个数组为两个之和大小，归并到这个数组
        Long[] temp = new Long[end2 - start1 + 1];
        int k = 0;
        while (i <= end1 && j <= end2) {
            if (s[i] > s[j]) {
                temp[k] = s[j];
                k++;
                j++;
            } else {
                temp[k] = s[i];
                k++;
                i++;
            }
        }
        // 将剩余的元素加入temp中
        while (i <= end1) {
            temp[k] = s[i];
            k++;
            i++;
        }
        while (j <= end2) {
            temp[k] = s[j];
            k++;
            j++;
        }
        // 将temp中数据转移到原数组中
        for (Long element : temp) {
            s[start1] = element;
            start1++;
        }
    }
}
